<?php

namespace App\Console\Commands;

use App\Jobs\user\BuildUserSuperior;
use App\Models\User;
use App\Models\user\UserSuperior;
use Illuminate\Console\Command;

class Superior extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'superior';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'app maintain command';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $users = User::get();

        foreach ($users as $user){

            if ($user->superior_id){
                $map['user_id'] = $user->id;
                $d = UserSuperior::where($map)->first();
                if (!$d){
                    BuildUserSuperior::dispatch($user);
                }
            }
        }

    }



}
